package com.hr.reactive.threading;

import com.hr.reactive.common.Utils;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

/**
 * @author Administrator
 */
public class Lec03Parallel {
    public static void main(String[] args) {
        Flux.range(1,10)
                .parallel(3 ).runOn(Schedulers.parallel())
                .map(Lec03Parallel::process)
               // .sequential()
                .subscribe(Utils.subscriber());

        Utils.sleepSeconds(5000);
    }
    private static int process(int i){
        System.out.println("time consuming task: "+i);
        Utils.sleepSeconds(1000);
        return i*2;
    }
}
